<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function myAxios() {
            return new Promise((resolve, reject) => {
                let xhr = new XMLHttpRequest()
                xhr.open('get', 'https://hmajax.itheima.net/api/province')
                xhr.send()
                xhr.addEventListener('loadend', function () {
                    //检查响应状态码是否在 200 到 299 之间，是表示请求成功。
                    if (xhr.status >= 200 && xhr.status < 300) {
                        // 成功，给promise对象的value赋值为 xhr.response
                        resolve(xhr.response)
                    } else {
                        // 失败，给promise对象的reason赋值为 '失败'
                        reject('失败')
                    }
                })
            })
        }
        myAxios()
            .then(res => {
                console.log(res);
            })
            .catch(err => {
                console.log(err);
            })
    </script>
</body>

</html>